Thr_chsl = input()
lst_frm_thr_chsl = Thr_chsl.split()
spsk_int_frm = ['0','1', '2', '3','4','5','6','7','8','9']
spsk_wrd_frm = ['zero', 'one', 'two','three','four','five','six','seven','eight', 'nine']
fl_nmb = 0
while True:
    if lst_frm_thr_chsl[0] == 'zero':
        print("Wrong input")
        break
    if len(lst_frm_thr_chsl) != 3:
        print("Wrong input")
        break
    for i in range(3):
        if len(str(lst_frm_thr_chsl[i])) < 3:
            print("Wrong input")
            break
    fl_nmb = int(spsk_int_frm[spsk_wrd_frm.index(lst_frm_thr_chsl[0])] + spsk_int_frm[spsk_wrd_frm.index(lst_frm_thr_chsl[1])] + spsk_int_frm[spsk_wrd_frm.index(lst_frm_thr_chsl[2])])
    break
prst_chsl_pls = fl_nmb
prst_chsl_mns = fl_nmb
razn_pls = 0
razn_mns = 0
razn2p = 1
razn2m = 1
fns_raz_pls = 0
fns_raz_mns = 0
deli_fn_pls = 2
deli_fn_mns = 2
while razn2p != 0:
    while deli_fn_pls != prst_chsl_pls -1:
        if prst_chsl_pls % deli_fn_pls ==0:
            razn_pls +=1
        deli_fn_pls += 1
        if  razn_pls > 0:
            prst_chsl_pls += 1
            deli_fn_pls +=1
            razn_pls = 0
            razn2p +=1
            fns_raz_pls =razn2p -1
        if (deli_fn_pls == prst_chsl_pls-2) and (razn_pls ==0):
            razn2p =0
while razn2m != 0:
    while deli_fn_mns != prst_chsl_mns -1:
        if prst_chsl_mns % deli_fn_mns ==0:
            razn_mns +=1
        deli_fn_mns += 1
        if  razn_mns > 0:
            prst_chsl_mns -= 1
            deli_fn_mns = 2
            razn_mns = 0
            razn2m +=1
            fns_raz_mns =razn2m -1
        if (deli_fn_mns == prst_chsl_mns-2) and (razn_mns ==0):
            razn2m =0
if fns_raz_mns>fns_raz_pls:
    print(prst_chsl_pls)
if fns_raz_mns<fns_raz_pls:
    print(prst_chsl_mns)
if fns_raz_mns == fns_raz_pls:
    print(prst_chsl_mns)
